package cn.xy.controller;

import cn.xy.entity.User;
import cn.xy.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletRequest;

/**
 * 用户控制器
 * @author Kiven
 */
@Controller
@RequestMapping("/user")
public class UserController {

    @Autowired
    private UserService userService;

    @RequestMapping("register")
    public String register(User user) {
        userService.register(user);
        return "index";
    }

    @RequestMapping("index")
    public String showIndex(HttpServletRequest request) {
        request.setAttribute("name", "Kiven");
        return "index";
    }

    @RequestMapping("showLogin")
    public String showLogin() {
        return "pages/login";
    }
    @RequestMapping("login")
    public String login(String username, String password) {
        System.out.println("username: " + username);
        System.out.println("password: " + password);
        return "index";
    }

    @RequestMapping("showRegister")
    public String showRegister() {
        return "pages/register";
    }


}
